﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace MCPlatform.Test.ParsingDLL
{
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct StrMTPA16DefaultConfidData
    {
        public float fCL = default(float);

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fTVT1 = new float[4];

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fTVT2 = new float[4];

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
        public float[] fVTI = new float[5];

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fVTT1 = new float[4];

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fVTT2 = new float[4];

     //   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fVTT3 = new float[4];

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fVTT4 = new float[4];

     //   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
        public ushort[] u16DPixAddr = new ushort[24];

     //   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
        public byte[] u8DPixMask = new byte[24];

        public byte u8DPixNum = default(byte);

     //   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
        public byte[] u8Reg = new byte[11];

        public byte u8eplison = default(byte);

    //    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public byte[] u8DeviceID = new byte[4];

    //    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
        public byte[] u8SN = new byte[8];

     //   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
        public byte[] u8ProdDesc = new byte[64];

        public float fGlobalCoe1 = default(float);
        public float fGlobalCoe2 = default(float);
        public ushort u16DataFlag = default(ushort);

     //   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
        public float[] fT2VT = new float[5];

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fT2VT1 = new float[4];

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fT2VT2 = new float[4];

      //  [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fT2VT3 = new float[4];

       // [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public float[] fT2VT4 = new float[4];

        public StrMTPA16DefaultConfidData()
        {
        }
    }
    public partial class MFThermopileClass
    {
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "CreateMyClass")]
        public static extern IntPtr CreateMyClass();

        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "DeleteMyClass")]
        public static extern void DeleteMyClass(IntPtr obj);
        //把从探头读到的128字节配置信息更新到内部存储区（目前只有PTAT系数）
        // void StoreConfigDataFromSensorEEP(uint8_t* u8pEEPData);
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "StoreConfigDataFromSensorEEP")]
        // public static extern void StoreConfigDataFromSensorEEP(ref IntPtr obj,ref byte[] u8pEEPData);

        public static extern void StoreConfigDataFromSensorEEP( IntPtr obj, byte[] u8pEEPData);


        //把配置文件中的数据分别保存到系数坏点区和信息配置去
        //void UpdataDataFromConfigFile(strMTPA16DefaultConfidData_t strConfigData);
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "UpdataDataFromConfigFile")]
        public static extern void UpdataDataFromConfigFile( IntPtr obj, StrMTPA16DefaultConfidData strConfigData);


        //把内部数据存储区的系数坏点内容，共208字节导出，用于PC发送指令写入到探头EEPROM中
        //void ExportCoeffAndDPixData(uint8_t* u8pData);
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "ExportCoeffAndDPixData")]
        public static extern void ExportCoeffAndDPixData( IntPtr obj,  byte[] u8pData);


        //把内部数据存储区的配置数据导出，共128字节，用于PC发送指令写入到探头EEPROM中
        // void ExportConfigInfoData(uint8_t* u8pData);
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "ExportConfigInfoData")]
        public static extern void ExportConfigInfoData( IntPtr obj,  byte[] u8pData);


        //把温度计算系数+2字节CRC导出，共3074字节，用于PC发送指令写入到探头EEPROM中
        //void ExportPixCoeffAndCS(uint8_t* u8pData);
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "ExportPixCoeffAndCS")]
        public static extern void ExportPixCoeffAndCS( IntPtr obj,  byte[] u8pData);


        //把产品序列号更新到内部数据存储区（8字节),仅对OK的探头赋序列号,NG的探头不能给序列号
        // void UpdataSNToConfigInfo(uint8_t* u8pSN);
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "UpdataSNToConfigInfo", CallingConvention = CallingConvention.Cdecl)]
        public static extern void UpdataSNToConfigInfo( IntPtr obj, byte[] u8pSN);


        //暂存采样数据        第几个校准点(1,2,3)  校准黑体温度  该探头的采样数据[518字节]
        //void SaveSampledData(int CaliPointID, float Temp, uchar* data);
        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "SaveSampledData")]
        public static extern void SaveSampledData( IntPtr obj, int CaliPointID, float Temp, byte[] data);

        //计算探头像素修正系数
        //判断像素中的坏点,更新到坏点信息区
        //计算成功则返回1, 如果由于一些原因出现Fail,返回0
        //返回该探头的校准系数和校验码[3074字节]
        //uint8_t Calculate_PixelCorrectionCoefficient(uchar* PixijData);

        [System.Runtime.InteropServices.DllImportAttribute("MFDll1.dll", EntryPoint = "Calculate_PixelCorrectionCoefficient")]
        public static extern byte Calculate_PixelCorrectionCoefficient( IntPtr obj,  byte[] PixijData);

        [DllImport("MFDll1.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern float Calculib_MTPA_TAmb2V_MF(float fTAmb);




    }
}
